package hellopde.swt;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class SWTButtonExample {
	public static void main(String[] args) {
		Display display = new Display();

		final Shell shell = new Shell(display);
		shell.setText("Hello SWT");
		shell.setBounds(100, 100, 220, 200);
		// shell.setLayout(new FillLayout());
		//
		// FillLayout layout = new FillLayout(SWT.VERTICAL);
		// shell.setLayout(layout);
		// for (int i = 0; i < 8; i++) {
		// Button button = new Button(shell, SWT.NONE);
		// button.setText("Sample Text");
		// }

		// RowLayout layout = new RowLayout(SWT.VERTICAL);
		// shell.setLayout(layout);
		// for (int i = 0; i < 8; i++) {
		// Button button = new Button(shell, SWT.NONE);
		// button.setText("Sample Text");
		// }

		// GridLayout layout = new GridLayout(4, false);
		// shell.setLayout(layout);
		// for (int i = 0; i < 8; i++) {
		// Button button = new Button(shell, SWT.NONE);
		// button.setText("Sample Text");
		// }

		FormData formData = null;
		shell.setLayout(new FormLayout());

		Button cancelButton = new Button(shell, SWT.PUSH);
		cancelButton.setText("Cancel");
		formData = new FormData();
		formData.right = new FormAttachment(100, -5);
		formData.bottom = new FormAttachment(100, -5);
		cancelButton.setLayoutData(formData);

		Button okButton = new Button(shell, SWT.PUSH);
		okButton.setText("Ok");
		formData = new FormData();
		formData.right = new FormAttachment(cancelButton, -5);
		formData.bottom = new FormAttachment(100, -5);
		okButton.setLayoutData(formData);

		Text text = new Text(shell, SWT.MULTI | SWT.BORDER);
		formData = new FormData();
		formData.top = new FormAttachment(0, 5);
		formData.bottom = new FormAttachment(cancelButton, -5);
		formData.left = new FormAttachment(0, 5);
		formData.right = new FormAttachment(100, 5);
		text.setLayoutData(formData);

		// final List list = new List(shell, SWT.SINGLE);
		// list.setItems(new String[] { "First", "Second", "Third" });
		// list.addSelectionListener(new SelectionListener() {
		// @Override
		// public void widgetSelected(SelectionEvent e) {
		// String[] selected = list.getSelection();
		// if (selected.length > 0) {
		// // System.out.println("Selected : " + selected[0]);
		// }
		// }
		//
		// @Override
		// public void widgetDefaultSelected(SelectionEvent e) {
		// String[] selected = list.getSelection();
		// if (selected.length > 0) {
		// System.out.println("Default Selected: " + selected[0]);
		// }
		// }
		// });

		// final Text text = new Text(shell, SWT.MULTI);
		// text.addVerifyListener(new VerifyListener() {
		// public void verifyText(VerifyEvent event) {
		// event.doit = event.text.length() == 0
		// || Character.isDigit(event.text.charAt(0));
		// }
		// });

		// RadioGroupFieldEditor radioGroup = new
		// RadioGroupFieldEditor("Choice",
		// "Choose an option:", 1, new String[][] { { "Choice1", "ch1" },
		// { "Choice2", "ch2" }, { "Choice3", "ch3" } }, shell,
		// true);
		//
		// final Button button = new Button(shell, SWT.BOTTOM);
		// button.setText("Click!");
		// button.addSelectionListener(new SelectionAdapter() {
		// public void widgetSelected(SelectionEvent event) {
		// button.setText("I was Clicked");
		// }
		// });

		// Button arrow = new Button(shell, SWT.ARROW | SWT.LEFT);
		// arrow.setText("LEFT");
		//
		// Button arrow3 = new Button(shell, SWT.ARROW | SWT.TOP);
		// arrow3.setText("TOP");
		//
		// Button arrow4 = new Button(shell, SWT.ARROW | SWT.BOTTOM);
		// arrow4.setText("BOTTOM");
		//
		// Button arrow2 = new Button(shell, SWT.ARROW | SWT.RIGHT);
		// arrow2.setText("RIGHT");

		// Button[] checks = new Button[2];
		//		
		// checks[0] = new Button(shell, SWT.CHECK);
		// checks[0].setText("Choice 1");
		// checks[0].setLocation(10,5);
		// checks[0].pack();
		//		
		// checks[1] = new Button(shell, SWT.CHECK);
		// checks[1].setText("Choice 2");
		// checks[1].setLocation(10,30);
		// checks[1].pack();

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}